﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="grdRelationship.ascx.cs" Inherits="GUESTSMANAGEMENT.View.Event.grdRelationship" %>
<%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>
<%@ Register Src="~/View/Event/frmEditRelationship.ascx" TagName="eRelationship" TagPrefix="eRalation" %>

<ext:ScriptManagerProxy ID="ScriptManagerProxy" runat="server">
</ext:ScriptManagerProxy>

<script type="text/javascript">
    var openWindowRelationship = function()
    {
        var winGrdRelationship = <%= winGrdRelationship.ClientID %>;
        winGrdRelationship.show();
    }
    
    function alertMessage() {
        relationshipGrid = eval('<%=relationshipGrid.ClientID%>');
        if (relationshipGrid.hasSelection())
            return "Confirma Exclusão? <br> <b>" + relationshipGrid.getSelectionModel().getSelected().data.NMUSER + "</b><br> do Evento: <b>" + eventGridPanel.getSelectionModel().getSelected().data.NMEVENT;

    }

    var getEventIdEventUser = function(grid, rowIndex, columnIndex, e) {
        var t = e.getTarget();
        var record = grid.getStore().getAt(rowIndex);
        var columnId = grid.getColumnModel().getColumnId(columnIndex);
        var columnValue = grid.getColumnModel().getDataIndex(5);
        var columnValueUser = grid.getColumnModel().getDataIndex(6);
        var id = record.get(columnValue);
        <%=txt_idEventUser.ClientID %>.setValue(id);
    }
</script>

<ext:DesktopWindow ID="winGrdRelationship" runat="server" Maximizable="false" Collapsible="true" Icon="World" Title="Eventos" Width="480" Height="325">
    <Body>
        <ext:Hidden ID="txt_idUser" runat="server"></ext:Hidden>
        <ext:Hidden ID="txt_idEventUser" runat="server"></ext:Hidden>
        <ext:Hidden ID="txt_idEvent" runat="server"></ext:Hidden>
        <ext:Store ID="eventUserStore" runat="server" OnRefreshData="Refresh" RefreshAfterSaving="Auto">
            <Reader>
                <ext:JsonReader>
                    <Fields>
                        <ext:RecordField Name="CDEVENTUSER" />
                        <ext:RecordField Name="QTBF" />
                        <ext:RecordField Name="QTBM" />
                        <ext:RecordField Name="QTFF" />
                        <ext:RecordField Name="QTFM" />
                        <ext:RecordField Name="NMEVENT" />
                        <ext:RecordField Name="NMUSER" />
                        <ext:RecordField Name="CDUSER" />
                        <ext:RecordField Name="CDEVENT" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store> 
        <ext:FitLayout ID="FitLayout1" runat="server">
            <ext:GridPanel ID="relationshipGrid"
                runat="server"
                StoreID="eventUserStore"
                StripeRows="true"
                Width="470" 
                Height="295">
                <TopBar>
                    <ext:Toolbar ID="ToolBar1" runat="server">
                        <Items>
                            <ext:ToolbarButton ID="btnEditEventUser" runat="server" Icon="WorldEdit" Enabled="false">
                                <AjaxEvents>
                                    <Click OnEvent="EditEventUser">
                                        <ExtraParams>
                                            <ext:Parameter Name="id" Value="#{relationshipGrid}.getSelectionModel().getSelected().data.CDEVENTUSER" Mode="Raw" />
                                            <ext:Parameter Name="idUser" Value="#{relationshipGrid}.getSelectionModel().getSelected().data.CDUSER" Mode="Raw" />
                                            <ext:Parameter Name="idEvent" Value="#{relationshipGrid}.getSelectionModel().getSelected().data.CDEVENT" Mode="Raw" />
                                        </ExtraParams>
                                    </Click>
                                </AjaxEvents>
                                <ToolTips>
                                    <ext:ToolTip ID="ToolTipEditEventUser" runat="server" Html="Editar Convites"></ext:ToolTip>
                                </ToolTips>
                            </ext:ToolbarButton>
                            <ext:ToolbarButton ID="btnExcluirEventUser" runat="server" Icon="WorldDelete" Enabled="false">                     
                                <AjaxEvents>
                                    <Click OnEvent="ConfirmDeleteEventUser" >                                        
                                        <Confirmation ConfirmRequest="true" 
                                                      Title="Alerta"                                                                                                  
                                                      BeforeConfirm="config.confirmation.message = alertMessage()"                                                       
                                        />
                                        <ExtraParams>
                                            <ext:Parameter Name="id" Value="#{relationshipGrid}.getSelectionModel().hasSelection() ? #{relationshipGrid}.getSelectionModel().getSelected().data.CDEVENT : -1" Mode="Raw" />
                                            <ext:Parameter Name="idUser" Value="#{relationshipGrid}.getSelectionModel().hasSelection() ? #{relationshipGrid}.getSelectionModel().getSelected().data.CDUSER : -1" Mode="Raw" />
                                            <ext:Parameter Name="idEvent" Value="#{relationshipGrid}.getSelectionModel().hasSelection() ? #{relationshipGrid}.getSelectionModel().getSelected().data.CDEVENT : -1" Mode="Raw" />
                                        </ExtraParams>                                        
                                    </Click>
                                </AjaxEvents>
                                <ToolTips>
                                    <ext:ToolTip ID="ToolTipDeleteEventUser" runat="server" Html="Excluir Promoter da Relação"></ext:ToolTip>
                                </ToolTips>
                            </ext:ToolbarButton>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:Column ColumnID="userName" Header="Nome" Width="220" DataIndex="NMUSER" Sortable="true" />
                        <ext:Column ColumnID="BonusFeminino" Header="B. Fem" Align="Right" Width="60" DataIndex="QTBF" Sortable="true" />
                        <ext:Column ColumnID="BonusFeminino" Header="B. Mas" Align="Right" Width="60" DataIndex="QTBM" Sortable="true" />
                        <ext:Column ColumnID="BonusFeminino" Header="F. Fem" Align="Right" Width="60" DataIndex="QTFF" Sortable="true" />
                        <ext:Column ColumnID="BonusFeminino" Header="F. Mas" Align="Right" Width="60" DataIndex="QTFM" Sortable="true" />
                        <ext:Column ColumnID="CDEVENTUSER" Hidden="true" DataIndex="CDEVENTUSER" />
                        <ext:Column ColumnID="CDUSER" Hidden="true" DataIndex="CDUSER" />
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionMode" runat="server">
                        <Listeners>
                            <RowSelect Handler="#{btnExcluirEventUser}.enable(); #{btnEditEventUser}.enable();" />                             
                            <RowDeselect Handler="if (!#{relationshipGrid}.hasSelection()) { #{btnEditEventUser}.enable(); #{btnExcluirEventUser}.disable();} " />
                        </Listeners>                       
                    </ext:RowSelectionModel>
                </SelectionModel>
                <Listeners>
                    <CellDblClick />
                    <CellClick Fn="getEventIdEventUser" />
                </Listeners>
                <AjaxEvents>
                    <CellDblClick OnEvent="EditEventUser" Failure="Ext.MessageBox.alert('Erro Leitura Banco de Dados', 'Error ocorreu no Ajax Event!');">
                        <EventMask ShowMask="true" Msg="Carregando..." Target="CustomTarget" CustomTarget="={#{relationshipGrid}.body}" />
                        <ExtraParams>
                            <ext:Parameter Name="id" Value="#{relationshipGrid}.getSelectionModel().getSelected().data.CDEVENTUSER" Mode="Raw" />
                        </ExtraParams>
                    </CellDblClick>
                </AjaxEvents>
                <LoadMask ShowMask="true" />
                <SaveMask ShowMask="true" />
                <BottomBar>
                    <ext:PagingToolBar ID="PagingToolBar" runat="server" PageSize="10" StoreID="eventUserStore" />
                </BottomBar>
            </ext:GridPanel>
        </ext:FitLayout>
        <eRalation:eRelationship ID="eRalation" runat="server" />
    </Body>
</ext:DesktopWindow>

